package com.group.controller;
import com.group.entity.CommonResult;
import com.group.entity.wms.GoodsEntity;
import com.group.service.GoodsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.context.annotation.ScopeMetadata;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;
    @GetMapping("/findAll")
    public CommonResult<?> findAll(Integer page,Integer size){
        return CommonResult.success(this.goodsService.findAll(page,size),"请求成功");
    }
    /**
     * 根据储位id查询商品详情
     * @param positionId
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/findByPositionId")
    public CommonResult<?> findByPositionId(Long positionId,Integer page,
                                           Integer size){
        return CommonResult.success(this.goodsService.findByPosition(positionId,page,size),"请求成功");
    }

    @GetMapping("/findByNameLike")
    public CommonResult<?> findByNameLike(String keyWorld){
        return CommonResult.success(this.goodsService.findByNameLike(keyWorld),"请求成功");
    }
    /**
     * 删除储位信息
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public CommonResult<?>  delete(@RequestBody List<Long> ids){
       return this.goodsService.delete(ids)>=1? CommonResult.success(null,"删除成功"):CommonResult.error(null,"删除失败");
    }

    /**
     * 添加货品信息
     * @param goodsEntity
     * @return
     */
    @PostMapping("/add")
    public CommonResult<?> add(@RequestBody GoodsEntity goodsEntity){
        return this.goodsService.add(goodsEntity)>=1?CommonResult.success(null,"添加成功，请绑定储位信息"):CommonResult.error(null,"添加失败" );
    }
    @GetMapping("/findById/{goodsId}")
    public CommonResult<?> findById(@PathVariable("goodsId")Long goodsId){
        return CommonResult.success(this.goodsService.findById(goodsId),"请求成功");
    }


}
